import request from '@/util/request'

// 获取地址列表
export function listAddress(params, val) {
  const { index, size } = params
  var mark = 'address'
  if (val === 'push') {
    mark = 'pushAddress'
  }
  return request({
    url: `/${mark}/list/${index}/${size}.json`,
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_MALL
  })
}

// 获取地址列表
export function listAllAddress(val) {
  var mark = 'address'
  if (val === 'push') {
    mark = 'pushAddress'
  }
  return request({
    url: `/${mark}/list.json`,
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_MALL
  })
}

// 获取地址详细信息
export function getAddressInfo(id, val) {
  var mark = 'address'
  if (val === 'push-edit') {
    mark = 'pushAddress'
  }
  return request({
    url: `/${mark}/${id}.json`,
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_MALL
  })
}

// 新增地址
export function addAddress(params, val) {
  var mark = 'address'
  if (val === 'push-add') {
    mark = 'pushAddress'
  }
  return request({
    url: `/${mark}.json`,
    method: 'post',
    data: params,
    baseURL: process.env.VUE_APP_AJS_MALL
  })
}

// 删除地址
export function deleteAddress(id, val) {
  var mark = 'address'
  if (val === 'push-edit') {
    mark = 'pushAddress'
  }
  return request({
    url: `/${mark}/${id}.json`,
    method: 'delete',
    baseURL: process.env.VUE_APP_AJS_MALL
  })
}

// 修改地址
export function modifyAddress(params, val) {
  var mark = 'address'
  if (val === 'push-edit') {
    mark = 'pushAddress'
  }
  return request({
    url: `/${mark}.json`,
    method: 'put',
    data: params,
    baseURL: process.env.VUE_APP_AJS_MALL
  })
}
